<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
            <sec:authorize url='/my_claim_order.do'>
                <a class="mini-button" iconCls="icon-download" onclick="claim()">认领订单</a>
            </sec:authorize>
                <!-- 此处需要权限标签,用于区分财务人员为一个人还是多个人,多个人需要认领订单 -->
            <sec:authorize url='/wait_order_checking.do'>
                <a class="mini-button" iconCls="icon-ok" onclick="onOK()">通过</a>
            </sec:authorize>
            <sec:authorize url='/batch_check_line_import.do'>
                <a class="mini-button" iconCls="icon-upload" onclick="importLineDelivery()">批量导入</a>
            </sec:authorize>
            </td>
            <td style="white-space:nowrap;">
                                             开始时间(大于)：<input name="startTime"  class="mini-datepicker" style="width: 180px" showClearButton="true" showClose="true" oncloseclick="closeT" allowInput="false"/>
                                            结束时间(小于)：<input name="endTime" class="mini-datepicker" showClearButton="true" showClose="true" oncloseclick="closeT" style="width: 180px" allowInput="false"/>
                <a class="mini-button" onclick="search()">查询</a>
            </td>
        </tr>
    </table>        
</div>
<div class="mini-fit" >
	<div id="datagrid0921" class="mini-datagrid" idField="id" pageSize="20" allowAlternating="true"
		allowCellSelect="true" multiSelect="true" url="pending_checking_view.do?payType=15" style="width:100%;height: 100%">
		<div property="columns">
			<div type="indexcolumn"></div>
			<div type="checkcolumn" ></div>
			<div field="serialNum" width="20%" headerAlign="center" align="center">订单号</div>
			<div width="10%" headerAlign="center" align="center" renderer="orderDetailView">订单明细</div>
			<div field="createTime" width="20%" allowSort="true" dateFormat="yyyy-MM-dd HH:mm:ss" headerAlign="center" align="center">下单时间</div>
			<div field="name" width="10%" headerAlign="center" align="center">收货人</div>
			<div field="payment" width="10%" headerAlign="center" align="center">货款金额</div>
			<div field="freight" width="10%" headerAlign="center" align="center">运费</div>
			<div field="signTime" width="20%" allowSort="true" dateFormat="yyyy-MM-dd HH:mm:ss" headerAlign="center" align="center">签收时间</div>
		</div>
	</div>
</div>
<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid0921");
grid.load();

function search() {
	var startTime = mini.getbyName("startTime").getFormValue();
	var endTime = mini.getbyName("endTime").getFormValue();
	grid.load({startTime: startTime, endTime: endTime});
}

/*--- 多个财务人员认领操作 ---*/
function claim() {
	var rows = grid.getSelecteds();
    if (rows.length > 0) {
        if (confirm("确定认领选中记录？")) {
            var ids = [];
            for (var i = 0, l = rows.length; i < l; i++) {
                var r = rows[i];
                ids.push(r.id);
            }
            var orderId = ids.join(',');
            grid.loading("操作中，请稍后......");
            $.post("my_claim_order.do", {orderId: orderId}, function(text) {
            	if(text.success) {
            		mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "认领成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
            	} else {
            		mini.alert('认领失败,数据错误或包含已认领的订单,请重新认领');
            	}
                grid.reload();
            }, "json");
        }
    } else {
        mini.alert("请选中一条记录");
    }
}

/*--- 财务人员对账操作 ---*/
function onOK() {
	var rows = grid.getSelecteds();
    if (rows.length > 0) {
        if (confirm("确定通过选中记录？")) {
            var ids = [];
            for (var i = 0, l = rows.length; i < l; i++) {
                var r = rows[i];
                ids.push(r.id);
            }
            var orderId = ids.join(',');
            grid.loading("操作中，请稍后......");
            $.post("wait_order_checking.do", {orderId: orderId}, function(text) {
            	if(text.success) {
            		mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "对账成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
            	} else {
            		mini.alert('对账失败,数据错误或包含已对账的订单,请重新对账');
            	}
                grid.reload();
            }, "json");
        }
    } else {
        mini.alert("请选中一条记录");
    }
}

/*--- 导入批量对账 ---*/
function importLineDelivery(){
	if(grid.data.length == 0) {
		mini.alert("数据为空,无法导入!");
		return;
	} else {
		mini.open({
			url:"batch_check_line_import.do",
			title:"批量导入",width:320,height:280,
			ondestroy: function (action) {
	        	if(action.operate == 'succ'){
	        		mini.open({
	                    url: "orders_batch_warning_info.do",
	                    title: "返回详细", width: 550, height: 350,
	                    allowResize: false,
	                    onload: function () {
	                        var iframe = this.getIFrameEl();
	                        var data = { info: action.message };
	                        iframe.contentWindow.SetData(data);
	                    },
	                    ondestroy: function (action) {
	                    	grid.reload();
	                    }
	                });
	        	}
	        }
		});
	}
}

function closeT(e) {
	e.sender.setValue('');
	e.sender.setText('');
}

function orderDetailView() {
	return '<a style="width:150px;" href="javascript:Views()">订单明细</a>';
}

/*---查看订单详细信息---*/
function Views() {
	var row = grid.getSelected();
	if(row) {
		mini.open({
	        url: "order_detail_open_view.do",
	        title: "订单详细", width: 850, height: 600,
	        onload: function () {
	            var iframe = this.getIFrameEl();
	            var data = { id: row.id };
	            iframe.contentWindow.SetData(data);
	        },
	        ondestroy: function (action) {
	        	if(action == 'claim'){
	         		mini.showMessageBox({
	                     title: "提示",
	                     showModal:false,
	                     iconCls: "mini-messagebox-info",
	                     message: "认领成功!",
	                     timeout: 3000,
	                     x: 'right',
	                     y: 'bottom'
	                 });
	         		grid.reload();
	        	} else if(action == 'recon') {
	        		mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "对账成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
	 	            grid.reload();
	        	}
	        }
	    });
	} else {
		alert('请选择你要查看的信息!');
	}
}
</script>
</body>
</html>